package com.solotiger.okex.service.impl;

import com.solotiger.okex.dao.BaseInfoDao;
import com.solotiger.okex.domain.OkexBaseInfo;
import com.solotiger.okex.service.OkexBaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

@Service
public class OkexBaseInfoServiceImpl implements OkexBaseInfoService {

    @Autowired
    private BaseInfoDao baseInfoDao;

    @Override
    public int save(OkexBaseInfo okexBaseInfo) {
        //时间设置为一天前
        Date now = new Date();
        Calendar cd = Calendar.getInstance();
        cd.setTime(now);
        cd.add(Calendar.DATE, -1);//增加EXPIRE天
        okexBaseInfo.setOprationTime(cd.getTime());
        return baseInfoDao.save(okexBaseInfo);
    }

    @Override
    public int updateApiKey(String apikey, String secretKey, int userId) {
        System.out.println(apikey);
        return baseInfoDao.updateApiKey(apikey, secretKey, userId);
    }

    @Override
    public int updateBase(float radix, float increase, float initialMoney, int userId) {
        return baseInfoDao.updateBase(radix, increase, initialMoney, userId);
    }

    @Override
    public OkexBaseInfo findByUserId(Integer userId) {
        return baseInfoDao.findByUserId(userId);
    }

    @Override
    public int updateMoney(float money, Date oprationTime, int userId) {
        return baseInfoDao.updateMoney(money, oprationTime, userId);
    }

    @Override
    public int update(OkexBaseInfo info) {
        return baseInfoDao.update(info);
    }
}
